package com.cskaoyan.service;

import com.cskaoyan.bean.MarketOrderGoods;
import com.cskaoyan.bean.MarketOrderGoodsExample;
import com.cskaoyan.mapper.MarketOrderGoodsMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.TransactionUtil;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author stone
 * @date 2023/03/18 00:51
 */
public class OrderGoodsServiceImpl implements OrderGoodsService {
    SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
    @Override
    public List<MarketOrderGoods> queryByOid(Integer orderId) {
        MarketOrderGoodsExample example = new MarketOrderGoodsExample();
        example.createCriteria().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        MarketOrderGoodsMapper orderGoodsMapper = sqlSessionFactory.openSession().getMapper(MarketOrderGoodsMapper.class);
        return orderGoodsMapper.selectByExample(example);
    }

    @Override
    public int deleteByOrderId(Integer orderId) {
        MarketOrderGoodsMapper orderGoodsMapper = TransactionUtil.getMapper(MarketOrderGoodsMapper.class);
        MarketOrderGoods record = new MarketOrderGoods();
        record.setDeleted(true);
        MarketOrderGoodsExample example = new MarketOrderGoodsExample();
        example.createCriteria().andOrderIdEqualTo(orderId);
        return orderGoodsMapper.updateByExampleSelective(record, example);
    }
}
